{{extend './layout/index.html'}}

{{block 'body'}}
<!-- dynamic -->
<el-upload
  class="avatar-uploader"
  action=""
  :show-file-list="false"
  :http-request="upload">
  <img v-if="imageUrl" :src="imageUrl" class="avatar">
  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
{{/block}}

{{block 'script'}}
<script>
(function () {
  new Vue({
    el: '#app',
    data () {
      return {
        imageUrl: ''
      }
    },
    methods: {
      async upload ({file}) {
        const formData = new FormData()
        if (!file) return 
        formData.append('file', file)
        const { data } = await axios.post('/admin/upload', formData)
        this.imageUrl = data.path
      }
    }
  })
})()
</script>
{{/block}}